package bookez.model.businessobject;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

@NamedQueries ({
		
	@NamedQuery(
		name = "Route.findAll",
		query = "from Route"
	),//end query findAll
	
	@NamedQuery( 
		name = "Route.findByFromCity",
		query = "from Route as route where route.fromCity like :city"
	),//end query findByFromCity
	
	@NamedQuery(
		name = "Route.findByToCity",
		query = "from Route as route where route.toCity like :city"
	),//end query findByToCity
	
	@NamedQuery(
		name = "Route.findByCities",
		query = "from Route as route where route.fromCity like :fromCity and route.toCity like :toCity"
	)
	
})//end NamedQueries

@Entity
@Table ( 
	name = "route",
	uniqueConstraints = {
		@UniqueConstraint( columnNames = { "from_city", "to_city" } )
	}//end attribute uniqueConstraints
)//end @Table

public class Route extends BusinessObject implements Serializable {
	
	public static class NamedQueries {
		public static final String FIND_ALL			 = "Route.findAll";
		public static final String FIND_BY_FROM_CITY = "Route.findByFromCity";
		public static final String FIND_BY_TO_CITY	= "Route.findByToCity";
		public static final String FIND_BY_CITIES	= "Route.findByCities";
	}//end section NamedQueries

	
	@Id
	@GeneratedValue
	public Long getId() { return this.id; }
	public void setId( Long value ) { this.id = value; }
	
	@Column ( name = "from_city", nullable = false )
	public String getFromCity() { return this.fromCity; }
	public void setFromCity( String value ) { this.fromCity = value; }
	
	
	@Column ( name = "to_city", nullable = false )
	public String getToCity() { return this.toCity; }
	public void setToCity( String value ) { this.toCity = value; }
	
	@Override
	protected boolean blindlyEquals(Object obj) {
		// TODO Auto-generated method stub
		if( !(obj instanceof Route) ) { return false; }
		final Route other = (Route) obj;
		
		//boolean fromCityChecked = checkProperty( this.getFromCity(), other.getFromCity() );
		//boolean toCityChecked = checkProperty(this.getToCity(), other.getToCity() );
		boolean fromCityChecked = this.getFromCity().equalsIgnoreCase( other.getFromCity() );
		boolean toCityChecked 	= this.getToCity().equalsIgnoreCase( other.getToCity() );
		
		return processResult( new boolean[] { fromCityChecked, toCityChecked } );
	}//end method blindlyEquals
	
	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		addPropertyToHashCode( getFromCity() );
		addPropertyToHashCode( getToCity() );
		return toHashCode();
	}//end method hashCode
	
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		addInfo( "id", getId() );
		addInfo( "fromCity", getFromCity() );
		addInfo( "toCity", getToCity() );
		return createInfo();		
	}//end method toString
	
	// Instance Variables
	private Long id;
	private String fromCity;
	private String toCity;
	
	private static final long serialVersionUID = 6001374720424349138L;
	
}//end class Route
